<?php

namespace App\Admin\Repositories;

use App\Models\ProjectAgreement as Model;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Repositories\EloquentRepository;
use Illuminate\Support\Facades\DB;

class ProjectAgreement extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    public function get(Grid\Model $model)
    {
        $currProjectID = request()->input('project_id', 0);
        $currUserID = request()->input('uid', 0);

        return DB::table('project_agreement as a')
            ->select([
                'p.project_name', 'p.project_sn', 'p.project_code', 'p.company_short', 'p.company as our_company',
                'p.active_name', 'p.sponsor',
                'a.*',
                'c.company_name'
            ])
            ->leftJoin('project as p', 'a.project_id', '=', 'p.id')
            ->leftJoin('company as c', 'p.company_id', '=', 'c.id')
            ->where([
                'a.project_id' => $currProjectID,
                'a.user_id' => $currUserID
            ])
            ->orderBy('a.id', 'desc')
            ->paginate();
    }

    public static function getPayStatus()
    {
        return [
            0 => '待支付(待审核)',
            1 => '允许支付',
            2 => '已支付',
            -1 => '已驳回'
        ];
    }

    // 协议整体的审批流程
    public static function getFlowMap()
    {
        return [
            1 => 'audit_first', // 协议审核
            2 => 'audit_fee', // 劳务审核
        ];
    }

    public static function getAuditStatus($index = '')
    {
        $map = [
            'audit_fee' => [0 => '待审核', 1 => '通过', -1 => '驳回'],
            'audit_first' => [0 => '待审核', 1 => '通过', -1 => '驳回'],
        ];
        return $map[$index] ?? [];
    }
}





















